
#include <sstream>
#include <string>
#include <iostream>
#include <cstdlib>
/**
 * @brief 从 string 转到其它类型
 * 
 * @tparam T 需要显示给出转换类型 fromstring<double>("1.2");
 * @param str 
 * @return T 
 */
template<typename T> 
T FromString(const std::string& str)
{
    std::istringstream is{str};
    T t;
    if(!(is>>t)) {
        std::cerr << "bad cast from string" << "\n" << str << "\n";
        exit(EXIT_FAILURE);
    }
    return t;
}
